<?php
# header of each page
function head($title='',$meta_description='',$current='',$canonical='',$logo='') {
header("Content-type: text/html; charset=UTF-8");

	if(!$_SESSION["currency"]) $_SESSION["currency"] = 'USD';
	if(!$_SESSION["curr_sim"]) $_SESSION["curr_sim"] = '&#36;';
	if(!$_SESSION["currency_value"]) $_SESSION["currency_value"] = 1;	
	if($_SESSION["currency_value"] == 1) $_SESSION["curr_sim"] = '&#36;';

?>
<!DOCTYPE html>
<html xml:lang="bg-BG">
<head>
<title><?=$title?></title>
<meta name="description" content="<?=$meta_description?>">

<base href="<?=(($_SESSION['USER_SID'])?HTML_BASE_SSL:HTML_BASE)?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<?php if ($canonical) { ?>
<link rel="canonical" href="<?=HTML_BASE.$canonical?>">

<meta property="og:title" content="<?=$title?>">
<meta property="og:image" content="<?=HTML_BASE?>uploads/logos/<?=$logo?>">
<meta property="og:site_name" content="ELS Traveler">
<meta property="og:description" content="<?=$meta_description?>">

<?php } ?>
<link href="<?=HTML_BASE_SSL?>css/style.css?v=2" rel="stylesheet" type="text/css">
<link href="<?=HTML_BASE_SSL?>css/jquery.fancybox-1.3.4.css" rel="stylesheet" type="text/css" >
<link href="<?=HTML_BASE_SSL?>js/jquery.rating.css" type="text/css" rel="stylesheet" >
<link rel="shortcut icon" href="favicon.ico">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript" src="<?=HTML_BASE_SSL?>js/kipo.js"></script>
<script type="text/javascript" src="<?=HTML_BASE_SSL?>js/fb.js"></script>
<script type="text/javascript" src="<?=HTML_BASE_SSL?>js/currency.js?v=1"></script>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-37935423-1']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

<meta name="author" content="studiokipo.com">
</head>
<body id="bd">

<div id="fb-root"></div>
<script type="text/javascript" src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({
 appId  : '491675174214499',
 status : true, // check login status
 cookie : true, // enable cookies to allow the server to access the session
 xfbml  : true  // parse XFBML
});
</script>   

<div id="wrap"><div id="wrapin">
	
    <div id="top">
    	<div id="logo">
        	<a href="index.php"></a>
        </div>
		
		<?php if($current != 101) { ?>
        <select class="inputbox" id="currency">
			<option value="USD" <?=($_SESSION["currency"]=='USD')?"selected":""?> >$ USD</option>
			<option value="GBP" <?=($_SESSION["currency"]=='GBP')?"selected":""?> >£ GBP</option>
			<option value="EUR" <?=($_SESSION["currency"]=='EUR')?"selected":""?> >€ EUR</option>
        </select>
		<?php } ?>
	   	
        <div id="menu">
        	<ul class="menu">
            <li><a href="index.php">Home</a></li>
            <li><a href="schools.php">Schools</a></li>
            <li><a href="about.php">About us</a></li>
            <li><a href="faq.php">FAQ</a></li>
            <li><a href="contacts.php">Contacts</a></li>
        	</ul>
      	</div>
        
        <div id="social">
        	<a title="Like Us on Facebook" class="facebook" href="https://www.facebook.com/ESLTraveler" target="_blank"></a>
            <a title="Follow Us on Twitter" class="twitter" href="https://twitter.com/Apply4ESL" target="_blank"></a>
            <a title="+1 Us on Google+" class="google" href="https://plus.google.com/116800269469061926685/" target="_blank"></a>
        </div>
        
        
        <div id="profile">
			<a title="My Profile" class="myprofile" href="myprofile.php"></a>
            <?php if($_SESSION['USER_SID']) { ?>
            	    
				<?php if($_SESSION['course_order']['course_id']) { ?>
						<a title="You have unfinished application" class="cart" href="order.php"></a>
				<?php } 
					
					if(!$_SESSION['FB_ID']){ ?>
					<a title="Logout" class="logout" href="logout.php"></a>
				<?php }else{ ?>
					<a title="Logout" class="logout" onClick="logout();"></a>   
				<?php } ?>
            
			<?php  
			} ?>
        </div>
      
    </div>
    
    <?php
	if ($current==1) {
    ?>
	<script src="<?=HTML_BASE?>js/jquery.carouFredSel-6.2.0-packed.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $("#slider").carouFredSel({
			items       : 1,
			width: 960,
			height: 400,
			auto : {
				fx 			: "fade",
				easing      : "linear",
				duration    : 1000,
				timeoutDuration: 3000,
				pauseOnHover: true
			}
		});
    });
    </script>
    <div id="slideshow">
    	<div id="slider">
        	<img src="images/slideshow/img_1.jpg" alt="Your Travel and Study Adventure starts here!" width="960" height="400" />
            <img src="images/slideshow/img_2.jpg" alt="Find an excellent place to study English" width="960" height="400" />
            <img src="images/slideshow/img_3.jpg" alt="Meet new friends and find new opportunities" width="960" height="400" />
        </div>
    </div>
    <?php
	}
    ?>
    
    <div id="contentwrap">
    
<?php
}

# footer of each page
function foot() {
?>
	
    	<div id="footer">
        	<div id="footerleft">
            	&copy; <?=date('Y')?> <?=COMPANY_NAME?>. <br/>
        	</div>
            <div id="footerright">
            	<a href="http://studiokipo.com" target="_blank">Web Design Studio Kipo</a>
        	</div>
        </div>
        
    </div><!--#contentwrap-->

</div></div>

<!--Start of Zopim Live Chat Script-->
<script type="text/javascript">
window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
$.src='//cdn.zopim.com/?12Zxfy8D21Maf9tXqUIl1WS2DVqz1ejI';z.t=+new Date;$.
type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
</script>
<!--End of Zopim Live Chat Script-->

</body>
</html>
<?php
}

function get_user_profile($id)
{
	$sql = "SELECT first_name, last_name, fb_id FROM users WHERE user_id = '$id'";
	$result = query($sql);
	$row = mysql_fetch_object($result);
	$data = '';
	if($row->fb_id) $data .=  '<img name="user'.$id.'" src="http://graph.facebook.com/'.$row->fb_id.'/picture?width=50&height=50" width="60" height="60"/>'; 
	if(!$row->fb_id) $data .=  '<img name="user'.$id.'" src="images/no_avatar.gif" width="60" height="60"/>'; 
	$data .=  	'<br><b>'.$row->first_name.' '.$row->last_name.'</b>';
	return $data;			
}


function get_school_reviews($id)
{
	/*$sql = "SELECT AVG(facilities),AVG(location),AVG(teacher),
	AVG(personal),AVG(social),AVG(safety) FROM schools_reviews
	WHERE school_id = '$id' AND published" ;
	$result = query($sql);
	$row = mysql_fetch_object($result);
	$data = ($row->facilities + $row->location + $row->teacher +
	$row->personal + $row->social + $row->safety )/6 ;*/
	
	$sql = "SELECT AVG(facilities) AS fac , AVG(location) AS loc ,AVG(teacher) AS tch, AVG(personal) AS per,AVG(social) AS soc , AVG(safety) AS safe  FROM schools_reviews
	WHERE school_id = '$id' AND published" ;
	
	$row = mysql_fetch_assoc(query($sql));
	$rat = ($row['fac']+$row['loc']+$row['tch']+$row['per']+$row['soc']+$row['safe'])/6;
	
		$data ='';
	 for($i = 1; $i<6; $i++)
	 {
		 if($i <= round($rat,0)){ $data .= '<div class="star-select"></div>'; 
		 }else{$data .= '<div class="star-no-select"></div>';}
		 
	 }
	
	$sql = "SELECT COUNT(*) AS Num FROM schools_reviews
	WHERE school_id = '$id' AND published";
	
	$row = mysql_fetch_assoc(query($sql));
	return ' ('.$data.round($rat, 2).' &middot; '.$row["Num"].' reviews)';			
}


# a redirecting function that adds the session ID if cookies are disabled and stops the execution of the script
function redirect($location) {
	if (!$location) error("Missing arguments.");

	$a = parse_url($location);
	if (!isset($a['query'])) {
		$a['query'] = '';
	}
	
	$session_delimiter = ($a['query'])?'&':'?';
	header("Location: $location".addsession($session_delimiter));
	exit;
}

# adding the session_id when cookies are disabled
function addsession($symbol="?") {
	return (!isset($_COOKIE[session_name()])&&session_id())?$symbol.session_name()."=".session_id():"";
}

function escape($string,$encoding=false) {
  return mysql_real_escape_string( (($encoding)?encoding($string):$string) );
}

function encoding($string) {
  return iconv('ISO-8859-1', 'UTF-8', $string);
}

function sth($string) {
  return htmlspecialchars(stripslashes($string));
}

# checks whether an email is valid or not
function checkEmail($email) {
	return preg_match("/^[A-z0-9\.\-]+@(?:[A-z0-9\-]+\.)+[A-z0-9]{1,6}$/", $email);
}

# Cut a text to specified chracters length
function text_format($text, $length) {
	$str = '';
	$text_length = mb_strlen($text, "UTF-8");
	 
	if ($text_length < $length) {
		$str = $text;		
	} else {
		$position_end = strpos($text, ' ', $length);
		$str = substr($text, 0, ($position_end)?$position_end:$text_length);
	}
	
	return $str;
}

# debug function for dumping a variable value
function pp($var, $stop=false) {
  echo "<pre>";
  print_r($var);
  echo "</pre>";
  if ($stop) exit;
}

# Generate numbers
function generateNumber () {
  # start with a blank number
  $number = "";
  # define possible characters
  $possible = "0123456789"; 
  # pick a random character from the possible ones
  $number = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  # done!
  return $number;
}

# Convert numbers into strings with n zeros
function number_pad($number,$n) {
	return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}

?>